package net.pinnoocle.playshoppc.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.pinnoocle.playcommon.response.BaseResult;
import net.pinnoocle.playdao.entity.group.UpdateGroup;
import net.pinnoocle.playdao.entity.page.PageModel;
import net.pinnoocle.playdao.entity.shopPc.*;
import net.pinnoocle.playservice.service.impl.ScriptServiceImpl;
import net.pinnoocle.playservice.service.impl.ShopServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ye
 * @Description
 * @create 2021-10-21 16:45
 */

@RestController
@RequestMapping("/scriptLevel")
@Api(tags = "剧本难易级别管理")
public class ScriptLevelController {
    @Autowired
    ScriptServiceImpl scriptService;
    @Autowired
    ShopServiceImpl shopService;

    @GetMapping("levelListWithPage")
    @ApiOperation("剧本级别列表---分页")
    public BaseResult<PageModel<ScriptLevelListPageVo>> levelListWithPage(BaseShopSearch shopSearch){
        return new BaseResult<PageModel<ScriptLevelListPageVo>>().ok(scriptService.levelListWithPage(shopSearch));
    }

    @GetMapping("levelList")
    @ApiOperation("剧本级别列表")
    public BaseResult<List<ScriptLevelListVo>> levelList(){
        return new BaseResult<List<ScriptLevelListVo>>().ok(scriptService.levelList());
    }

    @PostMapping("saveLevel")
    @ApiOperation("剧本级别添加")
    public BaseResult<String> saveLevel(@Validated @RequestBody SaveScriptLevelParams params){
        boolean result = scriptService.saveLevel(params);
        if(result){
            return new BaseResult<String>().success("剧本级别添加成功");
        }
        return new BaseResult<String>().error("剧本级别添加失败");
    }

    @PostMapping("updateLevel")
    @ApiOperation("剧本级别编辑")
    public BaseResult<String> updateLevel(@Validated({UpdateGroup.class}) @RequestBody SaveScriptLevelParams params){
        boolean result = scriptService.updateLevel(params);
        if(result){
            return new BaseResult<String>().success("剧本级别编辑成功");
        }
        return new BaseResult<String>().error("剧本级别编辑失败");
    }

    @GetMapping("deleteLevel")
    @ApiOperation("剧本级别删除")
    public BaseResult<String> deleteLevel(@RequestParam("levelId") Integer levelId){
        boolean result = scriptService.deleteLevel(levelId);
        if(result){
            return new BaseResult<String>().success("剧本级别删除成功");
        }
        return new BaseResult<String>().error("剧本级别删除失败");
    }
}
